// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.ui;

import zombie.core.Core;
import zombie.network.GameClient;
import zombie.network.GameServer;

public final class SpeedControls extends UIElement {
    public static SpeedControls instance = null;
    public int CurrentSpeed = 1;
    public int SpeedBeforePause = 1;
    public float MultiBeforePause = 1.0F;
    float alpha = 1.0F;
    boolean MouseOver = false;
    public static HUDButton Play;
    public static HUDButton Pause;
    public static HUDButton FastForward;
    public static HUDButton FasterForward;
    public static HUDButton Wait;

    public SpeedControls() {
        this.x = 0.0;
        this.y = 0.0;
        byte _byte = 2;
        Pause = new SpeedControls.SCButton("Pause", 1.0F, 0.0F, "media/ui/Time_Pause_Off.png", "media/ui/Time_Pause_On.png", this);
        Play = new SpeedControls.SCButton(
            "Play", (float)(Pause.x + (double)Pause.width + (double)_byte), 0.0F, "media/ui/Time_Play_Off.png", "media/ui/Time_Play_On.png", this
        );
        FastForward = new SpeedControls.SCButton(
            "Fast Forward x 1", (float)(Play.x + (double)Play.width + (double)_byte), 0.0F, "media/ui/Time_FFwd1_Off.png", "media/ui/Time_FFwd1_On.png", this
        );
        FasterForward = new SpeedControls.SCButton(
            "Fast Forward x 2",
            (float)(FastForward.x + (double)FastForward.width + (double)_byte),
            0.0F,
            "media/ui/Time_FFwd2_Off.png",
            "media/ui/Time_FFwd2_On.png",
            this
        );
        Wait = new SpeedControls.SCButton(
            "Wait",
            (float)(FasterForward.x + (double)FasterForward.width + (double)_byte),
            0.0F,
            "media/ui/Time_Wait_Off.png",
            "media/ui/Time_Wait_On.png",
            this
        );
        this.width = (float)((int)Wait.x) + Wait.width;
        this.height = Wait.height;
        this.AddChild(Pause);
        this.AddChild(Play);
        this.AddChild(FastForward);
        this.AddChild(FasterForward);
        this.AddChild(Wait);
    }

    @Override
    public void ButtonClicked(String name) {
        zombie.GameTime.instance.setMultiplier(1.0F);
        if ("Pause".equals(name)) {
            if (this.CurrentSpeed > 0) {
                this.SetCurrentGameSpeed(0);
            } else {
                this.SetCurrentGameSpeed(5);
            }
        }

        if ("Play".equals(name)) {
            this.SetCurrentGameSpeed(1);
            zombie.GameTime.instance.setMultiplier(1.0F);
        }

        if ("Fast Forward x 1".equals(name)) {
            this.SetCurrentGameSpeed(2);
            zombie.GameTime.instance.setMultiplier(5.0F);
        }

        if ("Fast Forward x 2".equals(name)) {
            this.SetCurrentGameSpeed(3);
            zombie.GameTime.instance.setMultiplier(20.0F);
        }

        if ("Wait".equals(name)) {
            this.SetCurrentGameSpeed(4);
            zombie.GameTime.instance.setMultiplier(40.0F);
        }
    }

    public int getCurrentGameSpeed() {
        return !GameClient.bClient && !GameServer.bServer ? this.CurrentSpeed : 1;
    }

    public void SetCorrectIconStates() {
        if (this.CurrentSpeed == 0) {
            super.ButtonClicked("Pause");
        }

        if (this.CurrentSpeed == 1) {
            super.ButtonClicked("Play");
        }

        if (zombie.GameTime.instance.getTrueMultiplier() == 5.0F) {
            super.ButtonClicked("Fast Forward x 1");
        }

        if (zombie.GameTime.instance.getTrueMultiplier() == 20.0F) {
            super.ButtonClicked("Fast Forward x 2");
        }

        if (zombie.GameTime.instance.getTrueMultiplier() == 40.0F) {
            super.ButtonClicked("Wait");
        }
    }

    public void SetCurrentGameSpeed(int NewSpeed) {
        if (this.CurrentSpeed > 0 && NewSpeed == 0) {
            zombie.SoundManager.instance.pauseSoundAndMusic();
            zombie.SoundManager.instance.setMusicState("PauseMenu");
        } else if (this.CurrentSpeed == 0 && NewSpeed > 0) {
            zombie.SoundManager.instance.setMusicState("InGame");
            zombie.SoundManager.instance.resumeSoundAndMusic();
        }

        zombie.GameTime.instance.setMultiplier(1.0F);
        if (NewSpeed == 0) {
            this.SpeedBeforePause = this.CurrentSpeed;
            this.MultiBeforePause = zombie.GameTime.instance.getMultiplier();
        }

        if (NewSpeed == 5) {
            NewSpeed = this.SpeedBeforePause;
            zombie.GameTime.instance.setMultiplier(this.MultiBeforePause);
        }

        this.CurrentSpeed = NewSpeed;
        this.SetCorrectIconStates();
    }

    @Override
    public Boolean onMouseMove(double dx, double dy) {
        if (!this.isVisible()) {
            return false;
        } else {
            this.MouseOver = true;
            super.onMouseMove(dx, dy);
            this.SetCorrectIconStates();
            return Boolean.TRUE;
        }
    }

    @Override
    public void onMouseMoveOutside(double dx, double dy) {
        super.onMouseMoveOutside(dx, dy);
        this.MouseOver = false;
        this.SetCorrectIconStates();
    }

    @Override
    public void render() {
        super.render();
        if ("Tutorial".equals(Core.GameMode)) {
            Pause.setVisible(false);
            Play.setVisible(false);
            FastForward.setVisible(false);
            FasterForward.setVisible(false);
            Wait.setVisible(false);
        }

        this.SetCorrectIconStates();
    }

    @Override
    public void update() {
        super.update();
        this.SetCorrectIconStates();
    }

    public static final class SCButton extends HUDButton {
        private static final int BORDER = 3;

        public SCButton(String name, float x, float y, String texture, String highlight, UIElement display) {
            super(name, (double)x, (double)y, texture, highlight, display);
            this.width += 6.0F;
            this.height += 6.0F;
        }

        @Override
        public void render() {
            int _int = 3;
            if (this.clicked) {
                _int++;
            }

            this.DrawTextureScaledCol(null, 0.0, this.clicked ? 1.0 : 0.0, (double)this.width, (double)this.height, 0.0, 0.0, 0.0, 0.5);
            if (!this.mouseOver && !this.name.equals(this.display.getClickedValue())) {
                this.DrawTextureScaled(
                    this.texture, 3.0, (double)_int, (double)this.texture.getWidth(), (double)this.texture.getHeight(), (double)this.notclickedAlpha
                );
            } else {
                this.DrawTextureScaled(
                    this.highlight, 3.0, (double)_int, (double)this.highlight.getWidth(), (double)this.highlight.getHeight(), (double)this.clickedalpha
                );
            }

            if (this.overicon != null) {
                this.DrawTextureScaled(this.overicon, 3.0, (double)_int, (double)this.overicon.getWidth(), (double)this.overicon.getHeight(), 1.0);
            }
        }
    }
}
